import { getBaseUrl } from '@/assets/utils';
// import { post, get } from "../api/axios";
import instance from "../api/axios";

// 进入h5落地页
export const enter_loadH5 = (bizType, params, headers) =>
    new Promise((resolve, reject) => {
        const url = `${getBaseUrl(bizType)}/h5/openApi/v1.0/market-extension/clue-clientinfo/add`;
        instance({
            url,
            method: 'POST',
            data: params,
            headers: headers,
            transformRequest: data => JSON.stringify(data)
        })
            .then(res => {
                const { data } = res;
                resolve(data);
            })
            .catch(() => {
                reject('程序开小差了，请稍后再试');
            });
    })

// 通用回传
export const event_callback = (bizType, params, headers) =>
    new Promise((resolve, reject) => {
        const url = `${getBaseUrl(
            bizType
        )}/h5/openApi/v1.0/market-extension/event/common/callback`;
        instance({
            url,
            method: 'POST',
            data: params,
            headers: headers,
            transformRequest: data => JSON.stringify(data)
        })
            .then(res => {
                const { data } = res;
                resolve(data);
            })
            .catch(() => {
                reject('程序开小差了，请稍后再试');
            });
    })

// 查询订单
export const queryOrder = (bizType, params, headers) =>
    new Promise((resolve, reject) => {
        const url = `${getBaseUrl(
            bizType
        )}/koApi/v1.0/pay-trade/spread/pay/status/v2`;
        instance({
            url,
            method: 'GET',
            params,
            headers,
            transformRequest: data => JSON.stringify(data)
        })
            .then(res => {
                const { data } = res;
                resolve(data);
            })
            .catch(() => {
                reject('程序开小差了，请稍后再试');
            });
    })

// 发送短信验证码
export const getPhoneCode = (bizType, params, headers) =>
    new Promise((resolve, reject) => {
        const url = `${getBaseUrl(
            bizType
        )}/h5/openApi/v1.0/message/sms/send`;
        console.log(url);
        instance({
            url,
            method: 'POST',
            data: params,
            headers: headers,
            transformRequest: data => JSON.stringify(data)
        })
            .then(res => {
                const { data } = res;
                resolve(data);
            })
            .catch(() => {
                reject('程序开小差了，请稍后再试');
            });
    })

// 短信验证
export const queryCode = (bizType, params, headers) =>
    new Promise((resolve, reject) => {
        const url = `${getBaseUrl(
            bizType
        )}/h5/openApi/v1.0/message/captcha/verify`;
        instance({
            url,
            method: 'GET',
            params,
            headers,
            transformRequest: data => JSON.stringify(data)
        })
            .then(res => {
                const { data } = res;
                resolve(data);
            })
            .catch(() => {
                reject('程序开小差了，请稍后再试');
            });
    })

    // h5手机号表单提交
    export const getSubmitForm = (bizType, params, headers) =>
    new Promise((resolve, reject) => {
        const url = `${getBaseUrl(
            bizType
        )}/h5/openApi/v1.0/market-extension/clue-clientinfo/submitForm`;
        instance({
            url,
            method: 'POST',
            data: params,
            headers: headers,
            transformRequest: data => JSON.stringify(data)
        })
            .then(res => {
                const { data } = res;
                resolve(data);
            })
            .catch(() => {
                reject('程序开小差了，请稍后再试');
            });
    })
    
// 发起微信支付
export const wxPay = (bizType, params, headers) =>
new Promise((resolve, reject) => {
    const url = `${getBaseUrl(
        bizType
    )}/koApi/v1.0/pay-trade/spread/h5/pay/v2`;
    instance({
        url,
        method: 'POST',
        data: params,
        headers: headers,
        transformRequest: data => JSON.stringify(data)
    })
        .then(res => {
            const { data } = res;
            resolve(data);
        })
        .catch(() => {
            reject('程序开小差了，请稍后再试');
        });
})

